package com.ruoyi.rest.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.rest.domain.vo.EmployeeNumTreeVo;
import com.ruoyi.rest.domain.vo.TreeNameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.rest.mapper.SillRestMapper;
import com.ruoyi.rest.domain.SillRest;
import com.ruoyi.rest.service.ISillRestService;

/**
 * 员工请假表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-10
 */
@Service
public class SillRestServiceImpl implements ISillRestService 
{
    @Autowired
    private SillRestMapper sillRestMapper;

    /**
     * 查询员工请假表
     * 
     * @param id 员工请假表主键
     * @return 员工请假表
     */
    @Override
    public SillRest selectSillRestById(Long id)
    {
        return sillRestMapper.selectSillRestById(id);
    }

    /**
     * 查询员工请假表列表
     * 
     * @param sillRest 员工请假表
     * @return 员工请假表
     */
    @Override
    public List<SillRest> selectSillRestList(SillRest sillRest)
    {
        return sillRestMapper.selectSillRestList(sillRest);
    }

    /**
     * 新增员工请假表
     * 
     * @param sillRest 员工请假表
     * @return 结果
     */
    @Override
    public int insertSillRest(SillRest sillRest)
    {

        extracted(sillRest);
        extracted1(sillRest);
        return sillRestMapper.insertSillRest(sillRest);
    }
   //生成请假天数
    private static void extracted1(SillRest sillRest) {
        Date restStart = sillRest.getRestStart();
        Date restEnd = sillRest.getRestEnd();
        long l =( ((restEnd.getTime() - restStart.getTime())) / (24 * 60 * 60 * 1000));
        sillRest.setRestDay(l);
    }

    //生成年月
    private static void extracted(SillRest sillRest) {
        Date restStart = sillRest.getRestStart();
        //得到日期中的日
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        // 使用ISO_LOCAL_DATE_TIME格式解析日期时间
        String dateTimeString = dateFormat.format(restStart);
        // 将转换为的字符串进行拆分
        String[] split = dateTimeString.split("-");
        // 输出年月日
        sillRest.setRestYearmonth(split[0]+"年"+split[1]+"月");
    }

    /**
     * 修改员工请假表
     * 
     * @param sillRest 员工请假表
     * @return 结果
     */
    @Override
    public int updateSillRest(SillRest sillRest)
    {
        extracted(sillRest);
        extracted1(sillRest);
        return sillRestMapper.updateSillRest(sillRest);
    }

    /**
     * 批量删除员工请假表
     * 
     * @param ids 需要删除的员工请假表主键
     * @return 结果
     */
    @Override
    public int deleteSillRestByIds(Long[] ids)
    {
        return sillRestMapper.deleteSillRestByIds(ids);
    }

    /**
     * 删除员工请假表信息
     * 
     * @param id 员工请假表主键
     * @return 结果
     */
    @Override
    public int deleteSillRestById(Long id)
    {
        return sillRestMapper.deleteSillRestById(id);
    }

    @Override
    public List<EmployeeNumTreeVo> getXqTree() {

        List<EmployeeNumTreeVo> allFloor = sillRestMapper.getAllNum();
        return allFloor;
    }

    @Override
    public List<TreeNameVo> getNameTree(String employeeNum) {
        List<TreeNameVo> allFloor = sillRestMapper.getAllName(employeeNum);
        return allFloor;

    }
}
